package com.dynamic.model.service.impl;

import com.dynamic.model.model.po.RequestHead;
import com.dynamic.model.service.DynamicRequestServiceI;
import com.dynamic.model.util.redis.CacheManager;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class DynamicRequestServiceImpl implements DynamicRequestServiceI {


    public Object twoUrlPath(String host,String url,String path) {
        Map<String,RequestHead> map= (Map<String, RequestHead>) CacheManager.getInstance().getAttributeMapGlobal(host);
        if(!map.keySet().contains(url+path)){
            return null;
        }
        RequestHead request=map.get(url+path);
        String response=request.getRequestContent();
        for(int i=0;i<request.getParameters().size();i++){
            response=StringUtils.replaceOnce(response,"@para",request.getParameters().get(i).getParameterValue());
        }
        return null;
    }

    public Object oneUrlPath(String host,String url,String path) {
        Map<String,RequestHead> map= (Map<String, RequestHead>) CacheManager.getInstance().getAttributeMapGlobal(host);
        if(!map.keySet().contains(url+path)){
            return null;
        }
        RequestHead request=map.get(url+path);
        String response=request.getRequestContent();
        for(int i=0;i<request.getParameters().size();i++){
            response=StringUtils.replaceOnce(response,"@para",request.getParameters().get(i).getParameterValue());
        }
        return null;
    }


    public Object threeUrlPath(String host,String url,String path) {
        return null;
    }
}
